
#include<iostream>
#include<SDL2/SDL.h>
//#define SDL_MAIN_HANDLED
#include<SDL2/SDL_vulkan.h>
#include<vector>
#include"graphics/VKGraphics.h"
//#undef main

class iwt{
public:
    int width;
    int height;
};


int main(int argc, char* argv[]){
    std::cout<<"hello day01"<<std::endl;

    std::cout<<"iwt offset width :"<<offsetof(iwt,width)<<std::endl;
    std::cout<<"iwt offset height :"<<offsetof(iwt,height)<<std::endl;

    SDL_Window *window = nullptr;
    if (SDL_Init(SDL_INIT_EVERYTHING)<0)
    {
        return 1;
    }

    window = SDL_CreateWindow("vulkan",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,1200,700,SDL_WINDOW_RESIZABLE|SDL_WINDOW_VULKAN);
    if (!window){
        auto error = SDL_GetError();
        std::cout<<error<<std::endl;
        SDL_Quit();
        return 1;
    }
    unsigned int count = 0;


    SDL_Vulkan_GetInstanceExtensions(window,&count,nullptr);
    std::cout<<count<<std::endl;
    const char* names[count];
    SDL_Vulkan_GetInstanceExtensions(window,&count,names);


    // for (auto item :names)
    // {
    //      std::cout<<item<<std::endl;
    // }
    
    VKG::VKGraphics contex;
    
    contex.init(names,count,[&window](VkInstance instance){
        VkSurfaceKHR surfaces;
        SDL_Vulkan_CreateSurface(window,instance,&surfaces);
        return surfaces;
    });

    SDL_Renderer *render = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
    if (!render)
    { 
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 1;
    }
    SDL_Event event;
    bool isrunning = true;
    while (isrunning)
    {
        SDL_PollEvent(&event);
        switch (event.type)
        {
        case SDL_QUIT:
            std::cout<<"关闭"<<std::endl;
            isrunning= false;
            break;
        case SDL_KEYUP:
            std::cout<<event.key.keysym.sym<<std::endl;
            break;
        default:
          //  std::cout<<"啥也没干"<<std::endl;
            break;
        }
        contex.undateUBO();
        contex.draw();
    }
    contex.wait();
    SDL_DestroyRenderer(render);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}